﻿/// <reference path="jquery-1.7.1.js" />

//////////////////////////////////////////////////////////////////////////
// AralNovel Storage class
//////////////////////////////////////////////////////////////////////////

// Top-level storage class
ANStorage = function(){ };
ANStorage.prototype.constructor = ANStorage;
ANStorage.prototype.storageName = "Abstract Storage";
ANStorage.prototype.storageColor = "#888888";
ANStorage.prototype.errorDescription = "This is an abstract class.";
ANStorage.prototype.has = function (key) { return false; };
ANStorage.prototype.read = function (key) { throw "Cannot call an abstract method!"; };
ANStorage.prototype.write = function (key, data) { throw "Cannot call an abstract method!"; };
ANStorage.prototype.remove = function (key) { throw "Cannot call an abstract method!"; };

// Local Storage Class
function ANLocalStorage() {
	ANStorage.call(this);
	
	if(("localStorage" in window) && (window["localStorage"] != null)) {
		this.errorDescription = undefined;
	}
	else {
		this.errorDescription = "<font color='red'>This browser doesn't support local storage!</font>";
	}
}
ANLocalStorage.prototype = new ANStorage();
ANLocalStorage.prototype.constructor = ANLocalStorage;
ANLocalStorage.prototype.storageName = "Local Storage";
ANLocalStorage.prototype.storageColor = "#99ccaa";
ANLocalStorage.prototype.errorDescription = "The object should be initialized using a constructor.";
ANLocalStorage.prototype.has = function (key) {
	if (this.errorDescription) throw this.errorDescription;
	return (localStorage.getItem(key) != null);
};
ANLocalStorage.prototype.read = function (key) {
	if (this.errorDescription) throw this.errorDescription;
	return localStorage.getItem(key);
};
ANLocalStorage.prototype.write = function (key, data) {
	if (this.errorDescription) throw this.errorDescription;
	return localStorage.setItem(key, data);
};
ANStorage.prototype.remove = function (key) { 
	if (this.errorDescription) throw this.errorDescription;
	return localStorage.removeItem(key);
};
AralNovel.prototype.storages.push(new ANLocalStorage());

//